package com.kaiwukj.android.ufamily;

import android.content.Context;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.kaiwukj.android.mcas.di.component.AppComponent;
import com.kaiwukj.android.ufamily.app.MyApplication;
import com.kaiwukj.android.ufamily.mvp.model.AccountModel;
import com.kaiwukj.android.ufamily.utils.upload.OnUploadListener;
import com.kaiwukj.android.ufamily.utils.upload.UploadBean;
import com.kaiwukj.android.ufamily.utils.upload.UploadUtils;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

@RunWith(AndroidJUnit4.class)
public class UploadTest {

    // @Inject
    AccountModel mModel;
    //RxErrorHandler mErrorHandler;

    @Before
    public void init() {

        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();


        AppComponent appComponent = MyApplication.getInstance().getAppComponent();
        mModel = new AccountModel(appComponent.repositoryManager());

        /*mErrorHandler = RxErrorHandler.builder()
                .with(appContext)
                .responseErrorListener(new ResponseErrorListenerImpl())
                .build();*/
    }

    @Test
    public void uploadZGImage() {
        String filePath = "/storage/emulated/0/Android/data/com.kaiwukj.android.ufamily/files/Pictures/IMG_CMP_681F6F7411380AEDC481C86C4BEF47.jpeg";
        String token = "CGXFecxwFKD0FQtWrF8PhLN72nCC-tfGKzuXrs_j:v__UBNl2Md4S-UthmWTQ8JfqNIA=:eyJzY29wZSI6Imp5bC16ZzI6MTEuanBnIiwiZGVhZGxpbmUiOjE1OTI3OTQ5Mjd9";
        UploadUtils.getInstance().upload(filePath, "11.jpg", token, new OnUploadListener() {
            @Override
            public void onUploadImage(UploadBean result) {
                LogUtils.d("result-------------->" + GsonUtils.toJson(result));
            }

            @Override
            public void onUploadImages(List<UploadBean> results) {

            }

            @Override
            public void onError(int errCode, String errMsg) {
                LogUtils.e("onError------------------------>" + errCode + ":" + errMsg);
            }
        });
    }

}
